package server;

import java.io.Serializable;

public class Ship implements Serializable {

    Point[] points;
    Point poistion;
    int size;

    Ship(Point... x) {
        size = x.length;
        points = new Point[size - 1];

        poistion = x[0];

        for (int z = 1; z < size; z++) {
            points[z - 1] = x[z];
        }
    }

    public Point getPoistion() {
        return poistion;
    }

    public int[] drawShips() {
        int[] x = new int[size * 2 - 2];
        int i = 0;
        for (Point p : points) {
            x[i++] = p.getI() + poistion.getI();
            x[i++] = p.getJ() + poistion.getJ();
        }
        return x;
    }

    public int[] drawShips(int x, int y) {
        int[] array = new int[size * 2 - 2];
        int i = 0;
        for (Point p : points) {
            array[i] = p.getI()+x;
            array[i+1] = p.getJ()+y;
            i+=2;
        }
        return array;
    }

    public void setPoistion(Point poistion) {
        this.poistion = poistion;
    }

    public String toString() {
        String s = "";
        int x[][] = new int[4][4];
        for (Point p : points) {
            x[p.getI()][p.getJ()] = 1;
        }
        for (int q = 0; q < 4; q++) {
            for (int w = 0; w < 4; w++) {
                s += (x[q][w] == 1 ? "*" : " ");
            }
            s += "\n";
        }
        return s;
    }
    static final Ship squaredShip = new Ship(new Point(2, 2), new Point(0, 0), new Point(1, 0),
            new Point(0, 1), new Point(1, 1));
    static final Ship diagonallyShip = new Ship(new Point(0, 0), new Point(0, 0),
            new Point(1, 1), new Point(2, 2), new Point(3, 3));
    static final Ship zShip = new Ship(new Point(5, 0), new Point(0, 0), new Point(1, 0),
            new Point(1, 1), new Point(2, 1));
    static final Ship linearShip = new Ship(new Point(0, 0), new Point(0, 0), new Point(0, 1),
            new Point(0, 2), new Point(0, 3));
    static final Ship tShip = new Ship(new Point(4, 8), new Point(0, 1), new Point(1, 0),
            new Point(1, 1), new Point(2, 1));
}
